package com.summer.weekGame74;

public class test2 {
    public static void main(String[] args) {
        System.out.println(maximumSubsequenceCount("abdcdbc", "ac"));
    }
    public static long maximumSubsequenceCount(String text, String pattern) {
        long count = 0, count1 = 0, count2 = 0;
        for (char c : text.toCharArray()) {
            count += c == pattern.charAt(1) ? count1 : 0;
            count2 += c == pattern.charAt(1) ? 1 : 0;
            count1 += c == pattern.charAt(0) ? 1 : 0;
        }
        return count + Math.max(count1, count2);
    }
}
